package bTree.LeetCode;

public class 最大子数组和 {
    public int maxSubArray(int[] nums) {
        int maxSum=nums[0];
        int []dp=new int[nums.length];
        dp[0]=nums[0];
        for (int i=1;i<nums.length;i++){
            dp[i]=dp[i-1]<0?nums[i]:dp[i-1]+nums[i];
            maxSum=Math.max(maxSum,dp[i]);
        }
        return maxSum;
    }
}